﻿using Smokey.Client.Screens.Applications;
using Smokey.Client.Screens.Common;
using System;
using System.ComponentModel;
namespace Smokey.Client.Contexts {
    public class ViewModelContext : INotifyPropertyChanged {

        public MainWindow MainWindow { get; private set; }

        public event PropertyChangedEventHandler PropertyChanged;

        public ViewModelContext(MainWindow mainWindow) {
            if (mainWindow == null) {
                throw new InvalidOperationException("Main window must not be null");
            }

            MainWindow = mainWindow;
        }

        private object content;
        public object ContentControl {
            get {
                return content;
            }

            set {
                content = value;
                OnPropertyChanged("ContentControl");
            }
        }

        protected void OnPropertyChanged(string name) {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (handler != null) {
                handler(this, new PropertyChangedEventArgs(name));
            }
        }

        #region Navigation

        public void ShowApplicationSearchScreen() {
            var applicationSearchScreen = new ApplicationSearch();
            applicationSearchScreen.DataContext = new ApplicationSearchViewModel(this);
            ContentControl = applicationSearchScreen;
        }

        public void ShowViewApplicationScreen(int? applicationId) {
            var screen = new ViewApplication();
            screen.DataContext = new ViewApplicationViewModel(this, applicationId);
            ContentControl = screen;
        }

        public void ShowConnectionStringSetupScreen() {
            var screen = new ConnectionStringSetup();
            screen.DataContext = new ConnectionStringSetupViewModel(this);
            ContentControl = screen;
        }

        #endregion
    }
}
